package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class GenericDemo {
    public static void main(String[] args) {
        //泛型案例演示
        List<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
//        c.add(123);//编译错误
        for (int i = 0; i < c.size(); i++) {
            System.out.println(c.get(i));
        }

        Iterator<String> it=c.iterator();
        while (it.hasNext()){
            String s=it.next();
            System.out.println(s);
        }

        for (String s:c) {
            System.out.println(s);
        }
    }
}
